# 批量下载JavaScript和CSS库文件

# 创建目录
New-Item -ItemType Directory -Force -Path "js"
New-Item -ItemType Directory -Force -Path "css"

Write-Host "开始下载JavaScript和CSS库文件..." -ForegroundColor Green

# 下载列表
$downloads = @(
    # Marked.js
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/marked/9.1.2/marked.min.js"
        Output = "js/marked.min.js"
        Name = "Marked.js"
    },
    
    # Prism.js CSS
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css"
        Output = "css/prism-tomorrow.min.css"
        Name = "Prism Tomorrow Theme CSS"
    },
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/line-numbers/prism-line-numbers.min.css"
        Output = "css/prism-line-numbers.min.css"
        Name = "Prism Line Numbers CSS"
    },
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/line-highlight/prism-line-highlight.min.css"
        Output = "css/prism-line-highlight.min.css"
        Name = "Prism Line Highlight CSS"
    },
    
    # Prism.js Core
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-core.min.js"
        Output = "js/prism-core.min.js"
        Name = "Prism Core"
    },
    
    # Prism.js Plugins
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/autoloader/prism-autoloader.min.js"
        Output = "js/prism-autoloader.min.js"
        Name = "Prism Autoloader"
    },
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/line-numbers/prism-line-numbers.min.js"
        Output = "js/prism-line-numbers.min.js"
        Name = "Prism Line Numbers"
    },
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/line-highlight/prism-line-highlight.min.js"
        Output = "js/prism-line-highlight.min.js"
        Name = "Prism Line Highlight"
    },
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/toolbar/prism-toolbar.min.js"
        Output = "js/prism-toolbar.min.js"
        Name = "Prism Toolbar"
    },
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js"
        Output = "js/prism-copy-to-clipboard.min.js"
        Name = "Prism Copy to Clipboard"
    },
    
    # 语言支持
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-javascript.min.js"
        Output = "js/prism-javascript.min.js"
        Name = "Prism JavaScript"
    },
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-python.min.js"
        Output = "js/prism-python.min.js"
        Name = "Prism Python"
    },
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-css.min.js"
        Output = "js/prism-css.min.js"
        Name = "Prism CSS"
    },
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-html.min.js"
        Output = "js/prism-html.min.js"
        Name = "Prism HTML"
    },
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-json.min.js"
        Output = "js/prism-json.min.js"
        Name = "Prism JSON"
    },
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-sql.min.js"
        Output = "js/prism-sql.min.js"
        Name = "Prism SQL"
    },
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-bash.min.js"
        Output = "js/prism-bash.min.js"
        Name = "Prism Bash"
    },
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-c.min.js"
        Output = "js/prism-c.min.js"
        Name = "Prism C"
    },
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-cpp.min.js"
        Output = "js/prism-cpp.min.js"
        Name = "Prism C++"
    },
    @{
        Url = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-java.min.js"
        Output = "js/prism-java.min.js"
        Name = "Prism Java"
    }
)

# 下载文件
$totalFiles = $downloads.Count
$currentFile = 0

foreach ($download in $downloads) {
    $currentFile++
    Write-Host "[$currentFile/$totalFiles] 下载 $($download.Name)..." -ForegroundColor Cyan
    
    try {
        Invoke-WebRequest -Uri $download.Url -OutFile $download.Output -UseBasicParsing
        Write-Host "  ✅ 成功: $($download.Output)" -ForegroundColor Green
    }
    catch {
        Write-Host "  ❌ 失败: $($download.Name) - $($_.Exception.Message)" -ForegroundColor Red
    }
}

Write-Host "`n下载完成！" -ForegroundColor Green
Write-Host "文件保存在以下目录：" -ForegroundColor Yellow
Write-Host "  - CSS文件: css/" -ForegroundColor Yellow
Write-Host "  - JS文件: js/" -ForegroundColor Yellow
